package com.ruoyi.labdata.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.labdata.domain.LabInstrumentScrap;
import com.ruoyi.labdata.mapper.LabInstrumentScrapMapper;
import com.ruoyi.labdata.service.ILabInstrumentScrapService;
import com.ruoyi.system.domain.Instrumentation;
import com.ruoyi.system.service.IInstrumentationService;

/**
 * 仪器报废Service业务层处理
 * 
 * @author winner pan
 * @date 2022-03-02
 */
@Service
public class LabInstrumentScrapServiceImpl implements ILabInstrumentScrapService 
{
    @Autowired
    private LabInstrumentScrapMapper labInstrumentScrapMapper;
    @Autowired
    private IInstrumentationService instrumentationService;
    /**
     * 查询仪器报废
     * 
     * @param scrapId 仪器报废ID
     * @return 仪器报废
     */
    @Override
    public LabInstrumentScrap selectLabInstrumentScrapById(Long scrapId)
    {
        return labInstrumentScrapMapper.selectLabInstrumentScrapById(scrapId);
    }

    /**
     * 查询仪器报废列表
     * 
     * @param labInstrumentScrap 仪器报废
     * @return 仪器报废
     */
    @Override
    public List<LabInstrumentScrap> selectLabInstrumentScrapList(LabInstrumentScrap labInstrumentScrap)
    {
        return labInstrumentScrapMapper.selectLabInstrumentScrapList(labInstrumentScrap);
    }

    /**
     * 新增仪器报废
     * 
     * @param labInstrumentScrap 仪器报废
     * @return 结果
     */
    @Override
    @Transactional
    public int insertLabInstrumentScrap(LabInstrumentScrap labInstrumentScrap){
    	Instrumentation instrumentation = new Instrumentation();
    	instrumentation.setInstrumentationId(labInstrumentScrap.getInstrumentationId());
    	instrumentation.setInstrumentationStatusOpt(Long.valueOf(4));
    	instrumentationService.updateInstrumentation(instrumentation);
    	labInstrumentScrap.setOperatorId(SecurityUtils.getLoginUser().getUser().getUserId());
        return labInstrumentScrapMapper.insertLabInstrumentScrap(labInstrumentScrap);
    }

    /**
     * 修改仪器报废
     * 
     * @param labInstrumentScrap 仪器报废
     * @return 结果
     */
    @Override
    public int updateLabInstrumentScrap(LabInstrumentScrap labInstrumentScrap)
    {
        return labInstrumentScrapMapper.updateLabInstrumentScrap(labInstrumentScrap);
    }

    /**
     * 批量删除仪器报废
     * 
     * @param scrapIds 需要删除的仪器报废ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentScrapByIds(Long[] scrapIds)
    {
        return labInstrumentScrapMapper.deleteLabInstrumentScrapByIds(scrapIds);
    }

    /**
     * 删除仪器报废信息
     * 
     * @param scrapId 仪器报废ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentScrapById(Long scrapId)
    {
        return labInstrumentScrapMapper.deleteLabInstrumentScrapById(scrapId);
    }
}
